package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.CollegeMapper;
import com.example.projectcode.model.College;
import com.example.projectcode.service.CollegeService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> implements CollegeService {
    @Override
    public List<College> selectAllColleges() {
        QueryWrapper<College> queryWrapper = new QueryWrapper<>();
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public int insertCollege(String collegeName) {
        College college = new College();
        college.setClName(collegeName);
        return baseMapper.insert(college);
    }

    @Override
    public int deleteCollegeById(Integer collegeId) {
        return baseMapper.delete(new QueryWrapper<College>().eq("Cl_id",collegeId));
    }

    @Override
    public int updateCollege(College college) {
        return baseMapper.update(college,new UpdateWrapper<College>().eq("Cl_id",college.getClId()));
    }
}
